<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分步表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <!--   引入核心js-->
    <script src="../../layui/layui.js"></script>
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/step-lay/step.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" lay-filter="form"
                                      style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">考试开始时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="test1" lay-verify="required"
                                                       name="enddate" placeholder="yyyy-MM-dd HH:mm:ss">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">考试结束时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="test2" lay-verify="required"
                                                       name="startdate" placeholder="yyyy-MM-dd HH:mm:ss">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">试卷名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="questionname" id="questionname"
                                                   lay-verify="required" autocomplete="off" placeholder="请输入试卷名称"
                                                   class="layui-input">
                                            <input type="hidden" name="questionid" id="questionid" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">考试专业</label>
                                        <div class="layui-input-block">
                                            <select name="majorid" lay-verify="required" lay-filter="aihao">
                                                <option value=""></option>
                                                <option value="601">计算机专业</option>
                                                <option value="603" selected="">软件专业</option>
                                                <option value="602">食品安全专业</option>
                                                <option value="604" selected="">食品国际专业</option>
                                                <option value="605">生活专业</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <form class="layui-form" lay-filter="zj-form">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">组卷方式</label>
                                            <div class="layui-input-block">
                                                <select name="interest" lay-filter="Rolloutmode">
                                                    <option value=""></option>
                                                    <option value="0">随机组卷</option>
                                                    <option value="1">选题组卷</option>
                                                </select>
                                            </div>
                                        </div>
                                    </form>
                                    <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">选择框</label>
                                            <div class="layui-input-block">
                                                <select name="interest" lay-filter="selectedtopic">
                                                    <option value=""></option>
                                                    <option value="0">选择填空题</option>
                                                    <option value="1">选择选择题</option>
                                                    <option value="2">选择判断题</option>
                                                    <option value="3">选择主观题</option>
                                                </select>
                                            </div>
                                        </div>
                                    </form>
                                    <!--                                    <div class="layui-form-item">-->
                                    <!--                                        <input type="hidden" name="questionid" id="questionid1"  class="layui-input">-->
                                    <!--                                    </div>-->
                                    <div class="layui-form-item"
                                         style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;确认完成
                                            </button>

                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div style="text-align: center;margin-top: 90px;">
                                <i class="layui-icon layui-circle"
                                   style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                    发布考试成功
                                </div>
                                <div style="font-size: 14px;color: #666;margin-top: 20px;">可在查看考试中查看详情</div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">再来一个</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div style="color: #666;margin-top: 30px;margin-bottom: 40px;padding-left: 30px;">
                        <h3>说明</h3><br>
                        <h4>填写试卷信息</h4>
                        <p>试卷名称暂时不可修改，填好再点下一步呦</p>
                        <br><h4>添加题目信息</h4>
                        <p>指定题目请选组卷方式为选题组卷！</p>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'step', 'laydate'], function () {
        var laydate = layui.laydate;
        var $ = layui.$,
            form = layui.form,
            step = layui.step;
        laydate.render({
            elem: '#test2'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#test1'
            , type: 'datetime'
        });
        form.on('select(Rolloutmode)', function (data) {
            if (data.value == '0') {

                form.on('select(selectedtopic)', function (data) {
                    if (data.value != '') {
                        layer.msg('请选择出卷方式为选题出卷', {icon: 5});

                    }
                })
                layer.open({
                    type: 1,
                    closeBtn: 0,
                    area: ['600px', '300px'],
                    content: '确定系统随机抽题吗',
                    btn: ['确定', '取消'],

                    yes: function (index) {
                        $.ajax({
                            type: "post",
                            url: "../../roa/random",
                            data: {"questionid": $("#questionid").val()},
                            success: function (data) {
                                layer.msg(data);
                                console.log(data);
                            }
                        });
                        layer.close(index);
                    }
                    , btn2: function (index) {
                        layer.close(index)
                        return false
                    }
                    , cancel: function (index) {
                        layer.close(index)
                        return false
                    }
                });


            } else if (data.value == '1') {
                form.on('select(selectedtopic)', function (data) {
                    if (data.value == '0') {
                        layer.open({
                            type: 2,
                            closeBtn: 0,
                            area: ['800px', '600px'],
                            content: 'Fillbacks.html',
                            btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']];
                                var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                if (checkStatus.data.length > 0) {
                                    // var data1 = {
                                    //     lists: checkStatus.data,
                                    //     questionid:$("#questionid").val(),
                                    // }
                                    // console.log(data1);

                                    let qnos = [];
                                    for (let i in checkStatus.data) {
                                        qnos.push(checkStatus.data[i].qno)
                                    }
                                    $.post('../../roa/chooseFillbacks', {
                                        "lists[]": qnos,
                                        questionid: $("#questionid").val()
                                    }, function (flag) {
                                        if (flag) {
                                            layer.msg('添加填空题成功', {icon: 6});
                                            table.reload("dg");//刷新表格
                                            layer.closeAll('page');//关闭当前对话框
                                        } else {
                                            layer.msg('添加填空题失败', {icon: 5});
                                        }
                                    })
                                }
                                layer.close(index);
                            }

                            , btn2: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                            , cancel: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                        })
                    } else if (data.value == '2') {
                        layer.open({
                            type: 2,
                            closeBtn: 0,
                            area: ['800px', '600px'],
                            content: 'torf.html',
                            btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']];
                                var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                if (checkStatus.data.length > 0) {
                                    // var data1 = {
                                    //     lists: checkStatus.data,
                                    //     questionid:$("#questionid").val(),
                                    // }
                                    // console.log(data1);
                                    let qnos = [];
                                    for (let i in checkStatus.data) {
                                        qnos.push(checkStatus.data[i].qno)
                                    }
                                    $.post('../../roa/chooseTorf', {
                                        "lists[]": qnos,
                                        questionid: $("#questionid").val()
                                    }, function (flag) {
                                        if (flag) {
                                            layer.msg('添加判断题成功', {icon: 6});
                                            table.reload("dg");//刷新表格
                                            layer.closeAll('page');//关闭当前对话框
                                        } else {
                                            layer.msg('添加判断题失败', {icon: 5});
                                        }
                                    })
                                }
                                layer.close(index);
                            }

                            , btn2: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                            , cancel: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                        })
                    } else if (data.value == '3') {
                        layer.open({
                            type: 2,
                            closeBtn: 0,
                            area: ['800px', '600px'],
                            content: 'Subjective.html',
                            btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']];
                                var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                if (checkStatus.data.length > 0) {
                                    // var data1 = {
                                    //     lists: checkStatus.data,
                                    //     questionid:$("#questionid").val(),
                                    // }
                                    // console.log(data1);

                                    let qnos = [];
                                    for (let i in checkStatus.data) {
                                        qnos.push(checkStatus.data[i].subid)
                                    }
                                    $.post('../../roa/chooseSubjective', {
                                        "lists[]": qnos,
                                        questionid: $("#questionid").val()
                                    }, function (flag) {
                                        if (flag) {
                                            layer.msg('添加主观题成功', {icon: 6});
                                            table.reload("dg");//刷新表格
                                            layer.closeAll('page');//关闭当前对话框
                                        } else {
                                            layer.msg('添加主观题失败', {icon: 5});
                                        }
                                    })
                                }
                                layer.close(index);
                            }

                            , btn2: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                            , cancel: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                        })
                    } else if (data.value == '1') {
                        layer.open({
                            type: 2,
                            closeBtn: 0,
                            area: ['800px', '600px'],
                            content: 'Choice.html',
                            btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']];
                                var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                if (checkStatus.data.length > 0) {
                                    // var data1 = {
                                    //     lists: checkStatus.data,
                                    //     questionid:$("#questionid").val(),
                                    // }
                                    // console.log(data1);

                                    let qnos = [];
                                    for (let i in checkStatus.data) {
                                        qnos.push(checkStatus.data[i].chid)
                                    }
                                    $.post('../../roa/chooseChoice', {
                                        "lists[]": qnos,
                                        questionid: $("#questionid").val()
                                    }, function (flag) {
                                        if (flag) {
                                            layer.msg('添加选择题成功', {icon: 6});
                                            table.reload("dg");//刷新表格
                                            layer.closeAll('page');//关闭当前对话框
                                        } else {
                                            layer.msg('添加选择题失败', {icon: 5});
                                        }
                                    })
                                }
                                layer.close(index);
                            }

                            , btn2: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                            , cancel: function (index, layero) {
                                layer.close(index)
                                return false
                            }
                        })
                    }
                })
            }


        })
        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '填写考试信息'
            }, {
                title: '添加题目信息'
            }, {
                title: '完成'
            }]
        });


        form.on('submit(formStep)', function (data) {
            // console.log("1"+data.field.questionid)
            if (data.field.questionid == "") {
                $.ajax({
                    type: "post",
                    url: "../../question/insertOne",
                    data: data.field,
                    success: function (data) {
                        layer.msg('添加试卷成功了哦！');
                        form.val('form', {
                            questionid: data.questionid,
                        })
                        form.render();
                        // form.val('form2', {
                        //     questionid1: data.questionid,
                        // })
                        // form.render();

                    }
                });

            }
            step.next('#stepForm');
            return false;
        });

        form.on('submit(formStep2)', function (data) {
            step.next('#stepForm');
            return false;
        });

        // form.on('submit(preview)', function (data){
        //     console.log("3"+data.field.questionid1)
        //     var index = layer.open({
        //         title: '预览试卷',
        //         type: 2,
        //         shade: 0.2,
        //         maxmin:true,
        //         shadeClose: true,
        //         area: ['100%', '100%'],
        //         content: '../teacherhtml/preview-paper.html',
        //         success: function (layero, index) {
        //             // 获取子页面的iframe
        //             var iframe = window['layui-layer-iframe' + index];
        //             // 向子页面的全局函数child传参
        //             iframe.child(data);
        //         }
        //     });
        //     $(window).on("resize", function () {
        //         layer.full(index);
        //     });
        //
        // })

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });
    })
</script>
</body>
</html>